package cn.anc.aonicardv.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import cn.anc.aonicardv.R;
import cn.anc.aonicardv.util.UIUtil;

/**
 * Created by yangdai on 2017/5/18.
 */

public class WarningDialog extends Dialog {

    private TextView warningWordTv;
    public TextView okTv;

    public WarningDialog(@NonNull Context context) {
        super(context);
        init();
    }

    public WarningDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        init();
    }

    protected WarningDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private void init() {
        setContentView(R.layout.dialog_warning);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        warningWordTv = (TextView) findViewById(R.id.tv_warning_word);
        okTv = (TextView) findViewById(R.id.tv_ok);
    }

    public WarningDialog setHint(String msg) {
        warningWordTv.setText(msg);
        return this;
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        Window window = getWindow();
        if (hasFocus && window != null) {
            View decorView = window.getDecorView();
            if (decorView.getHeight() == 0 || decorView.getWidth() == 0) {
                decorView.requestLayout();
                UIUtil.showToastShort("重新布局");
            }
        }
    }
}
